from datetime import datetime
from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()

class User(db.Model):
    """用户表"""
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True)

class Video(db.Model):
    """视频表"""
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(200))
    views = db.Column(db.Integer, default=0)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))  # 关联用户ID

class Ranking(db.Model):
    """榜单表"""
    id = db.Column(db.Integer, primary_key=True)
    rank_type = db.Column(db.String(50))  # 榜单类型
    content = db.Column(db.JSON)  # 榜单内容（JSON格式）
    created_at = db.Column(db.DateTime, default=datetime.utcnow)

class Follow(db.Model):
    """关注关系表"""
    follower_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
    followed_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
    created_at = db.Column(db.DateTime, default=datetime.utcnow)